package logic

import (
	"context"
	"gorm.io/gorm"
	"merchant-manager/models"

	"merchant-manager/userrpc/internal/svc"
	"merchant-manager/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpLogic {
	return &UpLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpLogic) Up(in *userrpc.UpRequest) (*userrpc.UpResponse, error) {
	// todo: add your logic here and delete this line
	merchant := models.Merchants{
		Model: gorm.Model{ID: uint(in.Id)},
		Name:  in.Name,
		Phone: in.Phone,
		Types: in.Types,
	}
	models.DB.Debug().Updates(&merchant)
	return &userrpc.UpResponse{
		Id:    int64(merchant.ID),
		Name:  merchant.Name,
		Phone: merchant.Phone,
		Types: merchant.Types,
	}, nil
}
